package com.elias.share.controller;

import com.elias.share.config.bean.FileInfo;
import com.elias.share.config.bean.SystemInfo;
import com.elias.share.enums.WebResultMsgEnum;
import com.elias.share.utils.WebResultUtil;
import com.elias.share.vo.WebResultVo;
import com.elias.share.vo.resp.FileInfoRespVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Log4j2
@Validated
@RequestMapping("sys")
@RestController
@ConditionalOnProperty(name = "system.enable", havingValue = "true")
public class SystemController {

    @Resource
    private FileInfo fileInfo;

    @Resource
    private SystemInfo systemInfo;

    @GetMapping("fileInfo")
    public WebResultVo<FileInfoRespVo> getFileInfo(@NotNull String secret) {
        if (systemInfo.getSecret().equals(secret)) {
            return WebResultUtil.success(new FileInfoRespVo(fileInfo));
        }
        return WebResultUtil.fail();
    }
}
